package com.snapp.util.registry;

import java.util.ServiceLoader;

import org.apache.log4j.Logger;

import com.snapp.util.factory.Factory;
import com.snapp.util.object.model.ObjectModel;
import com.snapp.util.service.model.ServiceModel;

public class Registry {
	static Logger log = Logger.getLogger(Registry.class);
	
	public static void registerObjects() {
		log.info("*Object discovery initialized");
		ServiceLoader<ObjectModel> models = ServiceLoader.load(ObjectModel.class);
		int count = 0;
    
		for (ObjectModel model : models) {
			log.info("  * " + model.getClass().getName());
			Factory.registerObject(model);
			count++;
		}

		log.info("    * " + count + " ObjectModel implementations found.");
	}

	public static void registerServices() {
		log.info("*Service discovery initialized");
		ServiceLoader<ServiceModel> models = ServiceLoader.load(ServiceModel.class);
		int count = 0;
    
		for (ServiceModel model : models) {
			log.info("  * " + model.getClass().getName());
			model.init();
			Factory.registerService(model);
			count++;
		}

		log.info("    * " + count + " ServiceModel implementations found.");
	}

}
